package day21;

import java.io.*;
import java.util.*;

/**
 * @author ZJX
 * @version 1.0
 * @descption
 * @since 2025/10/31 19:28
 */
public class Day18 {
    public String compressString(String s) {
        if (s.isEmpty()) {
            return "";
        }
        int i = 0;
        int n = s.length();
        StringBuilder sb = new StringBuilder();
        while (i < n) {
            char ch = s.charAt(i);
            int count = 1;
            while (i + 1 < n && s.charAt(i + 1) == ch) {
                count++;
                i++;
            }
            sb.append(ch);
            if (count > 1) {
                sb.append(count);
            }
            i++;
        }
        return sb.toString();
    }

    public int compress(char[] chars) {
        int n = chars.length;
        if (n == 0) return 0;

        int i = 0;
        int write = 0;
        while (i < n) {
            char ch = chars[i];
            int cur = 1;
            while (i + 1 < n && chars[i + 1] == ch) {
                cur++;
                i++;
            }
            chars[write++] = ch;
            if (cur > 1) {
                String countStr = Integer.toString(cur);
                for (char c : countStr.toCharArray()) {
                    chars[write++] = c;
                }
            }
            i++;
        }
        return write;
    }

    public static void main(String[] args) throws IOException {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(System.out);
        in.nextToken();
        int n = (int) in.nval;
        in.nextToken();
        int k = (int) in.nval;
        int[] sour = new int[n]; // 酸
        int[] sweet = new int[n]; // 甜
        for (int i = 0; i < n; i++) {
            in.nextToken();
            sour[i] = (int) in.nval;
        }
        for (int i = 0; i < n; i++) {
            in.nextToken();
            sweet[i] = (int) in.nval;
        }
        Orange[] oranges = new Orange[n];
        for (int i = 0; i < n; i++) {
            oranges[i] = new Orange(sour[i], sweet[i]);
        }
        Arrays.sort(oranges, (a, b) -> {
            if (a.sweet != b.sweet) {
                return Integer.compare(b.sweet, a.sweet);
            } else {
                return Integer.compare(a.sour, b.sour);
            }
        });
        long maxSweet = 0;
        long minSour = 0;
        for (int i = 0; i < k; i++) {
            maxSweet += oranges[i].sweet;
            minSour += oranges[i].sour;
        }
        out.print(minSour + " " + maxSweet);
        out.close();
    }

    static class Orange {
        int sour;
        int sweet;

        public Orange(int a, int b) {
            this.sour = a;
            this.sweet = b;
        }
    }

    /**
     * 计算01背包问题的结果
     *
     * @param V  int整型 背包的体积
     * @param n  int整型 物品的个数
     * @param vw int整型二维数组 第一维度为n,第二维度为2的二维数组,vw[i][0],vw[i][1]分别描述i+1个物品的vi,wi
     * @return int整型
     */
    public int knapsack(int V, int n, int[][] vw) {
        int[][] dp = new int[n + 1][V + 1]; // 前i个物品放入容量为j的背包的最大价值
        for (int i = 1; i <= n; i++) {
            // 体积与价值
            int v = vw[i - 1][0];
            int w = vw[i - 1][1];
            for (int j = 1; j <= V; j++) {
                if (j >= v) {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - v] + w);
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }
        return dp[n][V];
    }


    /**
     * 用给定数字组成不大于 N 的最大数字
     *
     * @param digits 数字组
     * @param N      大数字
     * @return 数字字符串
     */
    public String buildLargestNumber(int[] digits, String N) {
        if (digits.length == 0) return "";
        HashSet<Integer> set = new HashSet<>();
        for (int d : digits) {
            set.add(d);
        }
        List<Integer> list = new ArrayList<>(set);
        list.sort(Collections.reverseOrder());
        int lenN = N.length();
        String sameLen = buildSameLength(list, N, 0, true);
        if (!sameLen.isEmpty()) {
            return sameLen;
        }
        if (lenN == 1) {
            return "";
        }
        int maxDigit = list.get(0);
        if (maxDigit == 0) {
            return "0";
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < lenN - 1; i++) {
            sb.append(maxDigit);
        }
        return sb.toString();
    }

    /**
     * 递归构建与N同长度的最大数
     *
     * @param sortedDigits 从大到小排序的数字集合
     * @param N            目标数
     * @param index        当前处理的位数（从0开始）
     * @param isTight      是否受N当前位的约束（前几位均与N相同则为true）
     */
    private String buildSameLength(List<Integer> sortedDigits, String N, int index, boolean isTight) {
        int len = N.length();
        if (index == len) {
            // 成功构建了同长度的数
            return "";
        }

        int currentMax = isTight ? (N.charAt(index) - '0') : 9;
        for (int d : sortedDigits) {
            if (d > currentMax) {
                // 超过当前位上限，跳过
                continue;
            }
            // 选择d作为当前位，递归处理下一位
            boolean nextTight = isTight && (d == currentMax);
            String nextStr = buildSameLength(sortedDigits, N, index + 1, nextTight);
            if (nextStr != null) {
                // 下一位有效，拼接当前位和后续结果
                return d + nextStr;
            }
        }
        // 没有合适的数字，返回null表示当前路径无效
        return null;
    }

    public int compareVersion(String version1, String version2) {
        String[] v1 = version1.split("\\.");
        String[] v2 = version2.split("\\.");
        int len = Math.max(v1.length, v2.length);
        for (int i = 0; i < len; i++) {
            int m = (i < v1.length) ? Integer.parseInt(v1[i]) : 0;
            int n = (i < v2.length) ? Integer.parseInt(v2[i]) : 0;
            if (m > n) {
                return 1;
            }
            if (m < n) {
                return -1;
            }
        }
        return 0;
    }

    public int firstMissingPositive(int[] nums) {
        int n = nums.length;
        for (int i = 0; i < n; i++) {
            while (nums[i] > 0 && nums[i] <= n && nums[i] != nums[nums[i] - 1]) {
                int temp = nums[nums[i] - 1];
                nums[nums[i] - 1] = nums[i];
                nums[i] = temp;
            }
        }
        for (int i = 0; i < n; i++) {
            if (nums[i] != i + 1) {
                return i + 1;
            }
        }
        return n + 1;
    }

    public int longestValidParentheses(String s) {
        int maxLen = 0;
        Stack<Integer> stack = new Stack<>();
        stack.push(-1);
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '(') {
                stack.push(i);
            } else {
                stack.pop();
                if (stack.isEmpty()) {
                    stack.push(i);
                } else {
                    maxLen = Math.max(maxLen, i - stack.peek());
                }
            }
        }
        return maxLen;
    }

    public long countSubarrays(int[] nums, int k) {
        int max = 0;
        int n = nums.length;
        for (int i = 0; i < n; i++) {
            max = Math.max(max, nums[i]);
        }
        long ret = 0;
        int count = 0;
        int left = 0;
        for (int x : nums) {
            if (x == max) {
                count++;
            }
            while (count == k) {
                if (nums[left] == max) {
                    count--;
                }
                left++;
            }
            ret += left;
        }
        return ret;
    }

}

